#include "StdAfx.h"
#include "DxVertexFormat.h"
#include "DxRenderer.h"


DxVertexFormat::DxVertexFormat(void)
{
	//	typedef struct D3DVERTEXELEMENT9 {
	//  WORD Stream;
	//  WORD Offset;
	//  BYTE Type;
	//  BYTE Method;
	//  BYTE Usage;
	//  BYTE UsageIndex;
	//} D3DVERTEXELEMENT9, *LPD3DVERTEXELEMENT9;

	m_iOffsets[eVC_Position] = 0;
	m_iOffsets[eVC_Normal] = 12;
	m_iOffsets[eVC_TexCoord] = 24;
	m_iOffsets[eVC_BlendIndices] = 32;
	m_iOffsets[eVC_BlendWeights] = 36;

	D3DVERTEXELEMENT9 elements[] = {
		{ 0, m_iOffsets[eVC_Position],		D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
		{ 0, m_iOffsets[eVC_Normal],		D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
		{ 0, m_iOffsets[eVC_TexCoord],		D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
		{ 0, m_iOffsets[eVC_BlendIndices],	D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDINDICES, 0},
		{ 0, m_iOffsets[eVC_BlendWeights],	D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0},
		
		D3DDECL_END()
	};

	m_iSize = 52; //size of the vertex format in bytes

	DxRenderer::GetInstance()->GetDevice()->CreateVertexDeclaration(elements, &m_pDeclaration);
}


DxVertexFormat::~DxVertexFormat(void)
{
	if( m_pDeclaration )
		m_pDeclaration->Release();
}
